/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package snails;

import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.control.AbstractControl;
import java.util.ArrayList;
import shooter.Main;

/**
 *
 * @author ulfgur
 */
public class CannonBay extends AbstractControl
{
    ArrayList<Cannon> cannons;
    Vector3f position;
    Vector3f facing;
    Snail parentSnail;
    
    //TODO: determine if length is necessary as a permanent variable.
    float length;
    //TODO: determine if slots is necessary as a permanent variable.
    int slots;
    public CannonBay(Vector3f pos, Vector3f face, float len, int slo, Snail s)
    {
        cannons = new ArrayList<Cannon>();
        position = pos;
        facing = face;
        length = len;
        slots = slo;
        parentSnail = s;
        
        
    }
    
    public void initialize()
    {
        float gap = (length / slots);
        for(int a = 1; a <= slots; a++)
        {
            Cannon c = new Cannon(this);
            cannons.add(c);
            spatial.addControl(c);
            c.setFacing(facing);
            c.setLocation(position.x, position.y, position.z + (gap * a));
            System.out.println(c.getLocation());
            c.initialize();
        }
    }

    
    public void broadside()
    {
        for(Cannon c : cannons)
        {
            Vector3f cannonFacing = null;
            cannonFacing = spatial.getLocalRotation().mult(c.getFacing());
            Snail target = Main.world.pickSnail(parentSnail, c.blast.getWorldTranslation(), cannonFacing);
            int damage = c.fire();
            if(target != null)
            {
                target.damage(damage);
            }
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public ArrayList<Cannon> getCannons() {
        return cannons;
    }

    public void setCannons(ArrayList<Cannon> cannons) {
        this.cannons = cannons;
    }

    public Vector3f getPos() {
        return position;
    }

    public void setPos(Vector3f pos) {
        position = pos;
    }

    public Vector3f getFacing() {
        return facing;
    }

    public void setFacing(Vector3f facing) {
        this.facing = facing;
    }

    public float getLength() {
        return length;
    }

    public void setLength(float length) {
        this.length = length;
    }

    public int getSlots() {
        return slots;
    }

    public void setSlots(int slots) {
        this.slots = slots;
    }

    @Override
    protected void controlUpdate(float tpf)
    {
        
    }

    @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
        
    }
}